package thread.java20230112;

import java.util.concurrent.locks.ReentrantLock;

/**
 * lock的使用
 */
public class Demo50 {

    public static void main(String[] args) {
        ReentrantLock lock = new ReentrantLock();
        try {
            lock.lock();
            int sum = 1/0;
            //执行业务代码
            System.out.println("执行业务代码, 可能出现异常");
        }finally {
            lock.unlock();//unlock一定要放在finally执行
        }

    }
}
